package com.mtsmda.hibernateproject.h;

import java.util.GregorianCalendar;

import org.hibernate.Session;

import com.mtsmda.hibernateproject.h.domain.Event;
import com.mtsmda.hibernateproject.h.domain.Person;
import com.mtsmda.hibernateproject.h.util.HibernateUtil;

public class RunHibernate {
	
	public static void main(String[] args) {
		
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		
		Person person = new Person();
//		person.setAge(15);
//		person.setFirstname("Vasiliev");
//		person.setLastname("Vasilii");
		
		person = (Person) session.get(Person.class, new Long(1));
		
		System.out.println(person.getFirstname() + person.getLastname() + person.getAge());
//		person.getEmails().add("valiev.vasilii@mail.ru");
		Event event = new Event();
//		event.setTitle("Luk");
//		event.setDate(new GregorianCalendar(2014, 8, 10, 15, 30).getTime());
//		session.save(event);
		event = (Event) session.get(Event.class, new Long(1));
		person.getEvents().add(event);
		
		
//		session.save(person);
		session.getTransaction().commit();
		
		HibernateUtil.getSessionFactory().close();
		System.exit(0);
		
	}
	
}